home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / a_utils / expanded.lha / expanded / src / Object.C < prev    next >
C/C++ Source or Header  |  1992-03-19  |  8KB  |  281 lines

  1. //
  2. // Linear-Affine-Projective Geometry Package
  3. //
  4. // Object.C
  5. //
  6. // $Header$
  7. //
  8. // William J.R. Longabaugh 
  9. // University of Washington
  10. //
  11. // Implementation of the linear-affine-projective geometry
  12. // package described in William J.R. Longabaugh, "An Expanded
  13. // System for Coordinate-Free Geometric Programming", Master's 
  14. // thesis, University of Washington, 1992.
  15. //
  16. // Copyright (c) 1992, William J.R. Longabaugh
  17. //   Copying, use and development for non-commercial purposes permitted.
  18. //   All rights for commercial use reserved.
  19. //   This software is unsupported and without warranty; it is
  20. //   provided "as is".
  21. //
  22. // ***********************************************************************
  23.  
  24. #include <string.h>
  25. #include "Object.h"
  26.  
  27. const char *ast =
  28.        "**************************************************************\n";
  29.  
  30. //
  31. // Create a global error handler:
  32. //
  33.  
  34. ErrorHandler errh;
  35.  
  36. // ***********************************************************************
  37. // ***********************************************************************
  38. //
  39. // ErrorHandler class
  40. //
  41. // ***********************************************************************
  42. // ***********************************************************************
  43. //
  44. // Currently, there is nothing to do when constructing an Error Handler:
  45. //
  46.  
  47. ErrorHandler::ErrorHandler(void) {}
  48.  
  49. // ***********************************************************************
  50. //
  51. // Create a whole bunch of error exit calls.  Each takes a different
  52. // number of objects to print out.  Not very elegant, but type-safe:
  53. //
  54.  
  55. void ErrorHandler::ErrorExit(char *errloc, char *descript)
  56. {
  57.   cout << ast << "FATAL PROGRAM ERROR\n";
  58.   cout << "Error occurred in: " << errloc << "\n";
  59.   cout << "Error description: " << descript << "\n";
  60.   cout << ast;
  61.   abort();
  62. }
  63.  
  64. void ErrorHandler::ErrorExit(char *errloc, char *descript, Object &o1)
  65. {
  66.   cout << ast << "FATAL PROGRAM ERROR\n";
  67.   cout << "Error occurred in: " << errloc << "\n";
  68.   cout << "Error description: " << descript << "\n";
  69.   cout << "Contents of Relevant Objects:\n";
  70.   o1.debug_out(cout, ERR_IND); 
  71.   cout << ast;
  72.   abort();
  73. }
  74.  
  75. void ErrorHandler::ErrorExit(char *errloc, char *descript, Object &o1,
  76.                              Object &o2)
  77. {
  78.   cout << ast << "FATAL PROGRAM ERROR\n";
  79.   cout << "Error occurred in: " << errloc << "\n";
  80.   cout << "Error description: " << descript << "\n";
  81.   cout << "Contents of Relevant Objects:\n";
  82.   o1.debug_out(cout, ERR_IND); 
  83.   o2.debug_out(cout, ERR_IND); 
  84.   cout << ast;
  85.   abort();
  86. }
  87.  
  88. void ErrorHandler::ErrorExit(char *errloc, char *descript, Object &o1,
  89.                              Object &o2, Object &o3)
  90. {
  91.   cout << ast << "FATAL PROGRAM ERROR\n";
  92.   cout << "Error occurred in: " << errloc << "\n";
  93.   cout << "Error description: " << descript << "\n";
  94.   cout << "Contents of Relevant Objects:\n";
  95.   o1.debug_out(cout, ERR_IND); 
  96.   o2.debug_out(cout, ERR_IND); 
  97.   o3.debug_out(cout, ERR_IND); 
  98.   cout << ast;
  99.   abort();
  100. }
  101.  
  102. void ErrorHandler::ErrorExit(char *errloc, char *descript,
  103.                              Object &o1, Object &o2, Object &o3, Object &o4)
  104. {
  105.   cout << ast << "FATAL PROGRAM ERROR\n";
  106.   cout << "Error occurred in: " << errloc << "\n";
  107.   cout << "Error description: " << descript << "\n";
  108.   cout << "Contents of Relevant Objects:\n";
  109.   o1.debug_out(cout, ERR_IND); 
  110.   o2.debug_out(cout, ERR_IND); 
  111.   o3.debug_out(cout, ERR_IND); 
  112.   o4.debug_out(cout, ERR_IND); 
  113.   cout << ast;
  114.   abort();
  115. }
  116.  
  117. void ErrorHandler::ErrorExit(char *errloc, char *descript, Object &o1,
  118.                              Object &o2, Object &o3, Object &o4, Object &o5)
  119. {
  120.   cout << ast << "FATAL PROGRAM ERROR\n";
  121.   cout << "Error occurred in: " << errloc << "\n";
  122.   cout << "Error description: " << descript << "\n";
  123.   cout << "Contents of Relevant Objects:\n";
  124.   o1.debug_out(cout, ERR_IND); 
  125.   o2.debug_out(cout, ERR_IND); 
  126.   o3.debug_out(cout, ERR_IND); 
  127.   o4.debug_out(cout, ERR_IND); 
  128.   o5.debug_out(cout, ERR_IND); 
  129.   cout << ast;
  130.   abort();
  131. }
  132.  
  133. // ***********************************************************************
  134. // ***********************************************************************
  135. //
  136. // Object class
  137. //
  138. // ***********************************************************************
  139. // ***********************************************************************
  140. //
  141. // Stream output function for the object class.
  142. //
  143.   
  144. ostream& operator<<(ostream &c, Object &o)
  145. {
  146.   o.debug_out(c, 0);
  147.   return (c);
  148. }
  149.  
  150. // ***********************************************************************
  151. // ***********************************************************************
  152. //
  153. // ErrVal class
  154. //
  155. // ***********************************************************************
  156. // ***********************************************************************
  157. //
  158. // This class lets us print out important numeric values associated
  159. // with error conditions.
  160. //
  161. // ***********************************************************************
  162.  
  163. ErrVal::ErrVal(char *message, int val)
  164. {
  165.   text = new char[strlen(message) + 1];
  166.   strcpy(text, message);
  167.   isint = TRUE;
  168.   value = (Scalar)val;
  169. }
  170.  
  171. // ***********************************************************************
  172.  
  173. ErrVal::ErrVal(char *message, Scalar val)
  174. {
  175.   text = new char[strlen(message) + 1];
  176.   strcpy(text, message);
  177.   isint = FALSE;
  178.   value = val;
  179. }
  180.  
  181. // ***********************************************************************
  182.  
  183. ErrVal::~ErrVal(void)
  184. {
  185.   delete text;
  186. }
  187.  
  188. // ***********************************************************************
  189.  
  190. // To do debug printing:
  191.  
  192. void ErrVal::debug_out(ostream &c, int indent)
  193. {
  194.   char *ibloc = new char[indent + 1];
  195.   for (int i = 0; i < indent; i++) {
  196.     *(ibloc + i) = ' ';
  197.   }
  198.   *(ibloc + indent) = '\0';
  199.  
  200.   c << ibloc << ast;
  201.   c << ibloc << text << ((isint) ? (int)value : value) << "\n";
  202.   c << ibloc << ast;
  203.  
  204.   delete ibloc;
  205.   return;
  206. }
  207.  
  208. // ***********************************************************************
  209. // ***********************************************************************
  210. //
  211. // ErrType class
  212. //
  213. // ***********************************************************************
  214. // ***********************************************************************
  215. //
  216. // This class lets us print out enumerated types associated
  217. // with error conditions.
  218. //
  219. // ***********************************************************************
  220.  
  221. ErrType::ErrType(char *message, int val, EnumSet s)
  222. {
  223.   text = new char[strlen(message) + 1];
  224.   strcpy(text, message);
  225.   value = val;
  226.   set = s;
  227. }
  228.  
  229. // ***********************************************************************
  230.  
  231. ErrType::~ErrType(void)
  232. {
  233.   delete text;
  234. }
  235.  
  236. // ***********************************************************************
  237.  
  238. // To do debug printing:
  239.  
  240. void ErrType::debug_out(ostream &c, int indent)
  241. {
  242.   char *ibloc = new char[indent + 1];
  243.   for (int i = 0; i < indent; i++) {
  244.     *(ibloc + i) = ' ';
  245.   }
  246.   *(ibloc + indent) = '\0';
  247.  
  248.   c << ibloc << ast;
  249.   c << ibloc << text << " ";
  250.   switch (set) {
  251.     case SPACETYPES:
  252.       SpaceTypeOut(c, (SpaceType)value);
  253.       break;
  254.     case BASISTYPES:
  255.       BasisTypeOut(c, (BasisType)value);
  256.       break;
  257.     case GEOBTYPES:
  258.       GeObTypeOut(c, (GeObType)value);
  259.       break;
  260.     case MAPTYPES:
  261.       MapTypeOut(c, (MapType)value);
  262.       break;
  263.     case MULTITYPES:
  264.       MultiTypeOut(c, (MultiType)value);
  265.       break;
  266.     case SUBSETTYPES:
  267.       SubSetTypeOut(c, (SubSetType)value);
  268.       break;
  269.     case SRELTYPES:
  270.       SRelOut(c, (SRel)value);
  271.       break;
  272.   }
  273.   c << "\n";
  274.   c << ibloc << ast;
  275.  
  276.   delete ibloc;
  277.   return;
  278. }
  279.  
  280. // ***********************************************************************
  281.